﻿//////////////////////////////////////////////////////////////
// <auto-generated>This code was generated by LLBLGen Pro 5.9.</auto-generated>
//////////////////////////////////////////////////////////////
// Code is generated on: 
// Code is generated using templates: SD.TemplateBindings.SharedTemplates
// Templates vendor: Solutions Design.
//////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using LLBLGenPro.OrmCookbook.HelperClasses;
using LLBLGenPro.OrmCookbook.FactoryClasses;
using LLBLGenPro.OrmCookbook.RelationClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace LLBLGenPro.OrmCookbook.EntityClasses
{
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END
	/// <summary>Entity class which represents the entity 'Product'.<br/><br/></summary>
	[Serializable]
	public partial class ProductEntity : CommonEntityBase, Recipes.IProduct
    // __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
    // __LLBLGENPRO_USER_CODE_REGION_END	
	{
		private ProductLineEntity _productLine;

		// __LLBLGENPRO_USER_CODE_REGION_START PrivateMembers
		// __LLBLGENPRO_USER_CODE_REGION_END
		private static ProductEntityStaticMetaData _staticMetaData = new ProductEntityStaticMetaData();
		private static ProductRelations _relationsFactory = new ProductRelations();

		/// <summary>All names of fields mapped onto a relation. Usable for in-memory filtering</summary>
		public static partial class MemberNames
		{
			/// <summary>Member name ProductLine</summary>
			public static readonly string ProductLine = "ProductLine";
		}

		/// <summary>Static meta-data storage for navigator related information</summary>
		protected class ProductEntityStaticMetaData : EntityStaticMetaDataBase
		{
			public ProductEntityStaticMetaData()
			{
				SetEntityCoreInfo("ProductEntity", InheritanceHierarchyType.None, false, (int)LLBLGenPro.OrmCookbook.EntityType.ProductEntity, typeof(ProductEntity), typeof(ProductEntityFactory), false);
				AddNavigatorMetaData<ProductEntity, ProductLineEntity>("ProductLine", "Products", (a, b) => a._productLine = b, a => a._productLine, (a, b) => a.ProductLine = b, LLBLGenPro.OrmCookbook.RelationClasses.StaticProductRelations.ProductLineEntityUsingProductLineKeyStatic, ()=>new ProductRelations().ProductLineEntityUsingProductLineKey, null, new int[] { (int)ProductFieldIndex.ProductLineKey }, null, true, (int)LLBLGenPro.OrmCookbook.EntityType.ProductLineEntity);
			}
		}

		/// <summary>Static ctor</summary>
		static ProductEntity()
		{
		}

		/// <summary> CTor</summary>
		public ProductEntity()
		{
			InitClassEmpty(null, null);
		}

		/// <summary> CTor</summary>
		/// <param name="fields">Fields object to set as the fields for this entity.</param>
		public ProductEntity(IEntityFields2 fields)
		{
			InitClassEmpty(null, fields);
		}

		/// <summary> CTor</summary>
		/// <param name="validator">The custom validator object for this ProductEntity</param>
		public ProductEntity(IValidator validator)
		{
			InitClassEmpty(validator, null);
		}

		/// <summary> CTor</summary>
		/// <param name="productKey">PK value for Product which data should be fetched into this Product object</param>
		public ProductEntity(System.Int32 productKey) : this(productKey, null)
		{
		}

		/// <summary> CTor</summary>
		/// <param name="productKey">PK value for Product which data should be fetched into this Product object</param>
		/// <param name="validator">The custom validator object for this ProductEntity</param>
		public ProductEntity(System.Int32 productKey, IValidator validator)
		{
			InitClassEmpty(validator, null);
			this.ProductKey = productKey;
		}

		/// <summary>Private CTor for deserialization</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		protected ProductEntity(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
			// __LLBLGENPRO_USER_CODE_REGION_END
		}

		/// <summary>Creates a new IRelationPredicateBucket object which contains the predicate expression and relation collection to fetch the related entity of type 'ProductLine' to this entity.</summary>
		/// <returns></returns>
		public virtual IRelationPredicateBucket GetRelationInfoProductLine() { return CreateRelationInfoForNavigator("ProductLine"); }
		
		/// <inheritdoc/>
		protected override EntityStaticMetaDataBase GetEntityStaticMetaData() {	return _staticMetaData; }

		/// <summary>Initializes the class members</summary>
		private void InitClassMembers()
		{
			PerformDependencyInjection();
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
			// __LLBLGENPRO_USER_CODE_REGION_END
			OnInitClassMembersComplete();
		}

		/// <summary>Initializes the class with empty data, as if it is a new Entity.</summary>
		/// <param name="validator">The validator object for this ProductEntity</param>
		/// <param name="fields">Fields of this entity</param>
		private void InitClassEmpty(IValidator validator, IEntityFields2 fields)
		{
			OnInitializing();
			this.Fields = fields ?? CreateFields();
			this.Validator = validator;
			InitClassMembers();
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassEmpty
			// __LLBLGENPRO_USER_CODE_REGION_END

			OnInitialized();
		}

		/// <summary>The relations object holding all relations of this entity with other entity classes.</summary>
		public static ProductRelations Relations { get { return _relationsFactory; } }

		/// <summary>Creates a new PrefetchPathElement2 object which contains all the information to prefetch the related entities of type 'ProductLine' for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement2 implementation.</returns>
		public static IPrefetchPathElement2 PrefetchPathProductLine { get { return _staticMetaData.GetPrefetchPathElement("ProductLine", CommonEntityBase.CreateEntityCollection<ProductLineEntity>()); } }

		/// <summary>The ProductKey property of the Entity Product<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Product"."ProductKey".<br/>Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0.<br/>Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
		public virtual System.Int32 ProductKey
		{
			get { return (System.Int32)GetValue((int)ProductFieldIndex.ProductKey, true); }
			set { SetValue((int)ProductFieldIndex.ProductKey, value); }		}

		/// <summary>The ProductLineKey property of the Entity Product<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Product"."ProductLineKey".<br/>Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0.<br/>Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Int32 ProductLineKey
		{
			get { return (System.Int32)GetValue((int)ProductFieldIndex.ProductLineKey, true); }
			set	{ SetValue((int)ProductFieldIndex.ProductLineKey, value); }
		}

		/// <summary>The ProductName property of the Entity Product<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Product"."ProductName".<br/>Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50.<br/>Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String ProductName
		{
			get { return (System.String)GetValue((int)ProductFieldIndex.ProductName, true); }
			set	{ SetValue((int)ProductFieldIndex.ProductName, value); }
		}

		/// <summary>The ProductWeight property of the Entity Product<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Product"."ProductWeight".<br/>Table field type characteristics (type, precision, scale, length): Decimal, 10, 4, 0.<br/>Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Decimal> ProductWeight
		{
			get { return (Nullable<System.Decimal>)GetValue((int)ProductFieldIndex.ProductWeight, false); }
			set	{ SetValue((int)ProductFieldIndex.ProductWeight, value); }
		}

		/// <summary>The ShippingWeight property of the Entity Product<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Product"."ShippingWeight".<br/>Table field type characteristics (type, precision, scale, length): Decimal, 10, 4, 0.<br/>Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Decimal> ShippingWeight
		{
			get { return (Nullable<System.Decimal>)GetValue((int)ProductFieldIndex.ShippingWeight, false); }
			set	{ SetValue((int)ProductFieldIndex.ShippingWeight, value); }
		}

		/// <summary>Gets / sets related entity of type 'ProductLineEntity' which has to be set using a fetch action earlier. If no related entity is set for this property, null is returned..<br/><br/></summary>
		[Browsable(false)]
		public virtual ProductLineEntity ProductLine
		{
			get { return _productLine; }
			set { SetSingleRelatedEntityNavigator(value, "ProductLine"); }
		}

		// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
		// __LLBLGENPRO_USER_CODE_REGION_END

	}
}

namespace LLBLGenPro.OrmCookbook
{
	public enum ProductFieldIndex
	{
		///<summary>ProductKey. </summary>
		ProductKey,
		///<summary>ProductLineKey. </summary>
		ProductLineKey,
		///<summary>ProductName. </summary>
		ProductName,
		///<summary>ProductWeight. </summary>
		ProductWeight,
		///<summary>ShippingWeight. </summary>
		ShippingWeight,
		/// <summary></summary>
		AmountOfFields
	}
}

namespace LLBLGenPro.OrmCookbook.RelationClasses
{
	/// <summary>Implements the relations factory for the entity: Product. </summary>
	public partial class ProductRelations: RelationFactory
	{

		/// <summary>Returns a new IEntityRelation object, between ProductEntity and ProductLineEntity over the m:1 relation they have, using the relation between the fields: Product.ProductLineKey - ProductLine.ProductLineKey</summary>
		public virtual IEntityRelation ProductLineEntityUsingProductLineKey
		{
			get	{ return ModelInfoProviderSingleton.GetInstance().CreateRelation(RelationType.ManyToOne, "ProductLine", false, new[] { ProductLineFields.ProductLineKey, ProductFields.ProductLineKey }); }
		}

	}
	
	/// <summary>Static class which is used for providing relationship instances which are re-used internally for syncing</summary>
	internal static class StaticProductRelations
	{
		internal static readonly IEntityRelation ProductLineEntityUsingProductLineKeyStatic = new ProductRelations().ProductLineEntityUsingProductLineKey;

		/// <summary>CTor</summary>
		static StaticProductRelations() { }
	}
}
